/*
 * @Author: lyuan2018
 * @Date: 2020-03-18 10:44:34
 * @Last Modified by: lyuan2018
 * @Last Modified time: 2020-05-11 13:04:02
 */
/* 填空题打开--意见或建议Dialog */

import React, { Component } from 'react';
import { inject, observer } from 'mobx-react';
import { Button } from 'antd';
import { WeaDialog, WeaLocaleProvider, WeaRightMenu, WeaInputSearch } from 'ecCom';
import { VoteIcon } from '../../util';
import SuggestionContent from './SuggestionContent';

const getLabel = WeaLocaleProvider.getLabel;

@inject('voteResultStore')
@observer
export default class Suggestions extends Component {
  constructor(props) {
    super(props);
    this.prefixCls = 'vote-result-suggestion';
  }

  render() {
    const { visible, voteName, voteid, notShowExport, voteResultStore: { suggestionStore } } = this.props;
    const { loading, suggestTabble } = suggestionStore;
    const datas_rightMenu = notShowExport ? [] : [
      {
        key: 'BTN_EXPORT',
        content: getLabel('518717', '导出数据明细'),
        icon: <i className="icon-coms-leading-in" />,
        onClick: this.exportExcel,
      },
    ];
    const collectParams = {
      favname: `${getLabel(20042, '调查结果')} ：${voteName}`,
      favouritetype: 2,
      objid: 0,
      importantlevel: 1,
      link: 'wui/index.html#/main/voting/votingList',
      favname: getLabel(385160, '意见或建议'),
    };
    const buttons = notShowExport ? [] : [
      <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@9e4826@exportExcelBtn`} type="primary" onClick={this.exportExcel}>{getLabel('518717', '导出数据明细')}</Button>,
    ];
    return (
      <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@vmiayi`}
        visible={visible}
        title={getLabel(385160, '意见或建议')}
        icon={VoteIcon.iconClassName}
        iconBgcolor={VoteIcon.iconBgColor}
        style={{ width: 800, height: 540 }}
        className={this.prefixCls}
        onCancel={this.onCancel}
        loading={loading}
        buttons={buttons}
        moreBtn={{
          // datas: datas_rightMenu,
          collectParams,
        }}
        hasScroll
      >
        <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@m3tv4w`}
          datas={datas_rightMenu}
          collectParams={collectParams}
        >
          <div className={`${this.prefixCls}-search`}>
            <WeaInputSearch ecId={`${this && this.props && this.props.ecId || ''}_WeaInputSearch@7t4zt1`} onSearch={v => this.getDatas({ username: v }, true)} />
          </div>
          <div className={`${this.prefixCls}-main`}>
            <SuggestionContent ecId={`${this && this.props && this.props.ecId || ''}_SuggestionContent@7a80f1`}
              store={suggestionStore}
              tableStore={suggestTabble}
              voteid={voteid}
            />
          </div>
        </WeaRightMenu>
      </WeaDialog>
    );
  }

  getDatas = (params = {}, isSearch = false) => {
    const { voteResultStore: { suggestionStore } } = this.props;
    const { getTableList, setStoreState, listParams } = suggestionStore;
    if (!isSearch) setStoreState({ listParams: params });
    if (isSearch) params = { ...listParams, ...params };
    getTableList(params, isSearch ? true : '');
  }

  onCancel = () => {
    const { onCancel } = this.props;
    if (onCancel && typeof onCancel === 'function') onCancel();
  }

  exportExcel = () => {
    const { exportExcel } = this.props;
    if (exportExcel && typeof exportExcel === 'function') exportExcel();
  }
}
